import { useCallback, useEffect, useRef, useState } from 'react';

function useMethod(method, deps) {
  useCallback(method, deps);
}

function usePrevious(value) {
  const ref = useRef();
  useEffect(() => {
    ref.current = value;
  });
  return ref.current;
}

function useBoolean(initValue = false) {
  /**
   * 简化bool操作
   * */
  const [state, setState] = useState(!!initValue);
  const options = {
    on: () => setState(true),
    off: () => setState(false),
    toggle: () => setState((v) => !v),
  };
  return [state, options];
}

export { useMethod, usePrevious, useBoolean };
